
// 登录
window.onload = function () {
            $("btn").onclick = function () {
                let params = `username=${$("tel").value}&userpass=${$("pass").value}`;
                ajax({
                    url: "../php/login.php",
                    params: params,
                    method: "post",
                    callback: function (result) { //result就是xhr.responseText
                        console.log(result);
                        if (result == "success") {
                            // 登录成功，要保存cookie
                            setCookie("username", $("tel").value, 7);
                            location.href = "../html/first_page.html";
                        } else if (result == "fail") {
                            $("msg").innerHTML = "亲，登录失败，用户名或者密码不对";
                            $("msg").style.display = "block";
                            $("msg").style.color = "red";
                        }
                    }
                });
            }
        }
    
    
        function $(id) {
            return document.getElementById(id);
        }

